<template>
	<view class="container bg">
		<view class="radius-46 bg-1 mt-60">
			<u-field v-model="pass" :border-bottom="true" label-width="0" type="password" placeholder="请输入6位数字密码" placeholder-style="color:rgb(210,211,213);font-size:26rpx;">
			</u-field>
		</view>
		<view class="radius-46 bg-1">
			<u-field v-model="pass_confrim"  :border-bottom="false" label-width="0" placeholder="请再次输入密码" 
				placeholder-style="color:rgb(210,211,213);font-size:26rpx;" type="password">
			</u-field>
		</view>
		<u-button type="primary" class="confirmbtn" hover-class="none" @click="confirm">确认</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pass:'',
				pass_confrim:""
			}
		},
		onShow() {
			this.init();
		},
		methods: {
			init(){
				this.$http('api/user/setTradePass', {
					pass:'',
					pass_confrim:'',
				}).then(res => {
					console.log(res)
				})
			},
			confirm(){
				if (this.pass == '') {
					uni.showToast({
						title: "请输入密码",
						icon: 'none'
					})
					return;
				}
				if(this.pass.length!==6){
					uni.showToast({
						title: "密码输入不合法",
						icon: 'none'
					})
					return;
				}
				if (this.pass_confrim == '') {
					uni.showToast({
						title: "请再次输入密码",
						icon: 'none'
					})
					return;
				}
				if(this.pass!==this.pass_confrim){
					uni.showToast({
						title: "两次输入密码不一致",
						icon: 'none'
					})
					return;
				}
				this.$http('api/user/setTradePass', {
					pass: this.pass,
					pass_confrim: this.pass_confrim
				}, 'POST').then(res => {
					uni.showToast({
						title: '密码设置成功'
					})
					setTimeout(()=>{
						uni.navigateBack();
					},2000)
					uni.setStorageSync("psd", this.pass)
					
					// removeStorageSync('psd')
				})
			}
		}
	}
</script>

<style lang="less" scoped>
.container{
	width: 100%;
	height: 100vh;
	padding: 20rpx;
	.confirmbtn{
		color: #fff!important;
		background-color: #44ACFF !important;
		margin-top: 40rpx;
	}
}
::v-deep  .u-field{
		color:#333333!important;
		background-color: #fff;
	}
</style>
